/*(function () { const COOKIE_NAME = "oj_visitor_id"; const TRACK_ENDPOINT = "https://onlinejustice.info/Tracking/collect.php"; const FORM_SUBMIT_ENDPOINT = "https://onlinejustice.info/Tracking/form_submit.php"; const DURATION_ENDPOINT = "https://onlinejustice.info/Tracking/time.php"; const startTime = Date.now(); function getOrCreateVisitorId() { const existing = getCookie(COOKIE_NAME); if (existing) return existing; const newId = crypto.randomUUID(); setCookie(COOKIE_NAME, newId, 180); return newId; } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(";").shift(); } function setCookie(name, value, days) { const expires = new Date(Date.now() + days * 864e5).toUTCString(); document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`; } function getUTMParams() { const params = new URLSearchParams(window.location.search); const utm = {}; for (const [key, value] of params.entries()) { if (key.startsWith("utm_") || key.endsWith("clid")) { utm[key] = value; } } return utm; } function getTimezone() { return Intl.DateTimeFormat().resolvedOptions().timeZone || ""; } function getLocalTime() { return new Date().toLocaleString(); } function sendVisitData() { const visitorId = getOrCreateVisitorId(); const payload = { visitor_id: visitorId, page_url: window.location.href, referrer: document.referrer || null, utm: getUTMParams(), user_agent: navigator.userAgent, device_type: getDeviceType(), visited_at: new Date().toISOString(), timezone: getTimezone(), local_time: getLocalTime() }; fetch(TRACK_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); } function listenToFormSubmissions() { const visitorId = getOrCreateVisitorId(); document.querySelectorAll("form").forEach(form => { if (form.dataset.ojTracked) return; form.dataset.ojTracked = "true"; form.addEventListener("submit", () => { const fd = new FormData(form); const data = {}; fd.forEach((value, key) => { if (key in data) { if (!Array.isArray(data[key])) data[key] = [data[key]]; data[key].push(serializeValue(value)); } else { data[key] = serializeValue(value); } }); data.visitor_id = visitorId; data.page_url = window.location.href; fetch(FORM_SUBMIT_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), keepalive: true }); }); }); } function serializeValue(v) { if (v instanceof File) { return { filename: v.name, size: v.size, type: v.type || "application/octet-stream" }; } return typeof v === "string" ? v : String(v); } function observeNewForms() { const observer = new MutationObserver(() => { listenToFormSubmissions(); }); observer.observe(document.body, { childList: true, subtree: true }); } function getDeviceType() { const ua = navigator.userAgent.toLowerCase(); if (/mobile|android|iphone|ipad/.test(ua)) return "mobile"; if (/tablet/.test(ua)) return "tablet"; return "desktop"; } function sendDurationOnExit() { window.addEventListener("beforeunload", () => { const duration = Math.round((Date.now() - startTime) / 1000); const visitorId = getCookie(COOKIE_NAME); if (!visitorId) return; const payload = { visitor_id: visitorId, page_url: window.location.href, duration: duration }; navigator.sendBeacon(DURATION_ENDPOINT, JSON.stringify(payload)); }); } window.addEventListener("DOMContentLoaded", () => { sendVisitData(); listenToFormSubmissions(); observeNewForms(); sendDurationOnExit(); }); })(); */ //improved (function () { const COOKIE_NAME = "oj_visitor_id"; const TRACK_ENDPOINT = "https://onlinejustice.info/Tracking/collect.php"; const FORM_SUBMIT_ENDPOINT = "https://onlinejustice.info/Tracking/form_submit.php"; const PING_ENDPOINT = "https://onlinejustice.info/Tracking/ping.php"; const startTime = Date.now(); let activeTime = 0; let isActive = true; let maxScroll = 0; // Track scroll depth window.addEventListener("scroll", () => { const scrollPercent = Math.round((window.scrollY + window.innerHeight) / document.documentElement.scrollHeight * 100); if (scrollPercent > maxScroll) { maxScroll = scrollPercent; } }); // Track activity (mouse/keyboard/touch) ["mousemove", "keydown", "touchstart"].forEach(event => { window.addEventListener(event, () => { isActive = true; }); }); // Count active time every second setInterval(() => { if (isActive) { activeTime++; isActive = false; } }, 1000); function getOrCreateVisitorId() { const existing = getCookie(COOKIE_NAME); if (existing) return existing; const newId = crypto.randomUUID(); setCookie(COOKIE_NAME, newId, 180); return newId; } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(";").shift(); } function setCookie(name, value, days) { const expires = new Date(Date.now() + days * 864e5).toUTCString(); document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`; } function getUTMParams() { const params = new URLSearchParams(window.location.search); const utm = {}; for (const [key, value] of params.entries()) { if (key.startsWith("utm_") || key.endsWith("clid")) { utm[key] = value; } } return utm; } function sendVisitData() { const visitorId = getOrCreateVisitorId(); const payload = { visitor_id: visitorId, page_url: window.location.href, referrer: document.referrer || null, utm: getUTMParams(), user_agent: navigator.userAgent, device_type: getDeviceType(), visited_at: new Date().toISOString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, local_time: new Date().toLocaleString(), screen_width: window.screen.width, screen_height: window.screen.height, language: navigator.language, languages: navigator.languages, browser: navigator.userAgentData ? navigator.userAgentData.brands.map(b => b.brand).join(", ") : navigator.userAgent, platform: navigator.platform, touch_support: ('ontouchstart' in window) ? 1 : 0 }; fetch(TRACK_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); } function listenToFormSubmissions() { const visitorId = getOrCreateVisitorId(); document.querySelectorAll("form").forEach(form => { if (form.dataset.ojTracked) return; form.dataset.ojTracked = "true"; form.addEventListener("submit", () => { const fd = new FormData(form); const data = {}; fd.forEach((value, key) => { if (key in data) { if (!Array.isArray(data[key])) data[key] = [data[key]]; data[key].push(serializeValue(value)); } else { data[key] = serializeValue(value); } }); data.visitor_id = visitorId; data.page_url = window.location.href; fetch(FORM_SUBMIT_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), keepalive: true }); }); }); } function serializeValue(v) { if (v instanceof File) { return { filename: v.name, size: v.size, type: v.type || "application/octet-stream" }; } return typeof v === "string" ? v : String(v); } function observeNewForms() { const observer = new MutationObserver(() => { listenToFormSubmissions(); }); observer.observe(document.body, { childList: true, subtree: true }); } function getDeviceType() { const ua = navigator.userAgent.toLowerCase(); if (/mobile|android|iphone|ipad/.test(ua)) return "mobile"; if (/tablet/.test(ua)) return "tablet"; return "desktop"; } function startPingLoop() { setInterval(() => { const visitorId = getCookie(COOKIE_NAME); if (!visitorId) return; const payload = { visitor_id: visitorId, page_url: window.location.href, duration_seconds: Math.round((Date.now() - startTime) / 1000), active_time_seconds: activeTime, max_scroll: maxScroll }; fetch(PING_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); }, 2000); } window.addEventListener("DOMContentLoaded", () => { sendVisitData(); listenToFormSubmissions(); observeNewForms(); startPingLoop(); }); })();